import sys,time
import os
import pandas as pd
from Predict_2SJob import Predict_2SJob

def main(st_no,aim_st_s,avg_s_value_before,avg_s_value_after,wenjiang_coef,cao_dh_before,whisk_time_before
         ,iron_wt_net,coef1,coef2,coef3,coef4,coef5,iron_price,wenjiang_price,cao_price):
    result_list = []
    try:
        st_no = str(st_no)
        aim_st_s = float(aim_st_s)
        avg_s_value_before = float(avg_s_value_before)
        avg_s_value_after = float(avg_s_value_after)
        iron_wt_net = float(iron_wt_net)
        coef1 = float(coef1)
        coef2 = float(coef2)
        coef3 = float(coef3)
        coef4 = float(coef4)
        coef5 = float(coef5)
        iron_price = float(iron_price)
        wenjiang_price = float(wenjiang_price)
        cao_price = float(cao_price)
        success_tmp = True
        msg = ''
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    except Exception as e:
        success_tmp = False
        msg = f'invalid_parameter_type--{str(e)}'
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    if success_tmp:
        msg, result_list = Predict_2SJob(p_st_no=st_no, p_aim_st_s=aim_st_s, p_avg_s_value_before=avg_s_value_before,
                                         p_avg_s_value_after=avg_s_value_after, p_wenjiang_coef=wenjiang_coef,
                                         p_cao_dh_before=cao_dh_before, p_whisk_time_before=whisk_time_before,
                                         p_iron_wt_net=iron_wt_net, p_coef1=coef1, p_coef2=coef2,
                                         p_coef3=coef3, p_coef4=coef4, p_coef5=coef5, p_iron_price=iron_price,
                                         p_wenjiang_price=wenjiang_price, p_cao_price=cao_price).execute()
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        success_tmp = True
    success = success_tmp
    message = msg
    timestamp = timestamp
    table_1 = result_list
    return success, message, timestamp, table_1
if __name__ == '__main__':
    # 出钢记号，目标S，必选，确定钢种
    st_no = 'IH2554A2'
    aim_st_s = 20
    # 改变前的铁水S与改变后的铁水S，铁水包受铁净铁水量。必选
    avg_s_value_before = 30
    avg_s_value_after = 50
    iron_wt_net = 2700
    # 改变前的温降系数、脱硫剂单耗、脱硫时间，非必选，如果传入为空则根据模型自动计算
    # wenjiang_before = 34
    wenjiang_coef = 34/12
    cao_dh_before = 10
    whisk_time_before = 12
    xlsx_name = 'D:/repos/sicost/二炼钢成本参数.xlsx'
    df3 = pd.read_excel(xlsx_name)
    coef1 = df3['炉均扒渣量'].values[0]
    coef2 = df3['高炉渣'].values[0]
    coef3 = df3['扒渣量增加'].values[0]
    coef4 = df3['铁水包成本'].values[0]
    coef5 = df3['搅拌桨成本'].values[0]
    # 带铁成本
    iron_price = 3000
    # 温降成本
    wenjiang_price = 1
    # 脱硫剂成本
    cao_price = 0.91
    success, message, timestamp, table_1 = main(st_no,aim_st_s,avg_s_value_before,avg_s_value_after,wenjiang_coef,
                                                cao_dh_before,whisk_time_before,iron_wt_net,
                                                coef1,coef2,coef3,coef4,coef5,iron_price,wenjiang_price,cao_price)
    print(success, message, timestamp, table_1)
